export default {
    data() {
      return {
        searchItem: {
          searchKey: "",
        },
        showDevice: false,
        styles: {
          height: "calc(100% - 55px)",
          overflow: "auto",
          paddingBottom: "53px",
          position: "static",
        },
        formData: {},
        typeList:[{
            key:"10",
            title:"老师"
        },{
            key:"0",
            title:"学生"
        },{
            key:"1",
            title:"住校生"
        },{
            key:"2",
            title:"走读生"
        },
        {
            key:"99",
            title:"其他"
        }],
        columns: [
          {
            title: "分组名称",
            key: "title",
            fixed: "left",
            width: 150,
          },
          {
            title: "分组类型",
            key: "type",
            align: "center",
          },
          {
            title: "操作",
            key: "action",
            align: "center",
            width: 150,
            slot: "action",
            fixed: "right",
          },
        ],
        count: 0,
        total: 0,
        page: 1,
        pageSize: 10,
        datalist: [],
      };
    },
    computed: {
      user() {
        return this.$store.state.user;
      },
    },
    methods: {
      addAction() {
        this.formData = {};
        this.showDevice = true;
      },
      edit(index) {
        var model = this.datalist[index];
        this.formData = Object.assign({}, model);
        this.showDevice = true;
      },
      saveInfo() {
        this.$axios({
          url: "/group",
          method: "PUT",
          data: this.formData,
        }).then((res) => {
          if (res.code == 200) {
            this.formData = {};
            this.showDevice = false;
            this.getData();
          } else {
            this.$Message.error(res.msg);
          }
        });
      },
      pageChange(page) {
        this.page = page;
        this.getData();
      },
      pageSizeChange(pageSize) {
        this.pageSize = pageSize;
        this.getData();
      },
      getData() {
        this.$axios({
          url: `/group/list`,
          method: "POST",
          data: {
            page: this.page,
            pageSize: this.pageSize,
            searchKey: this.searchItem.searchKey,
          },
        }).then((res) => {
          if (res.code == 200) {
            this.datalist = res.data.list;
            this.total = res.data.total;
          }
        });
      },
      deleteInfo(index) {
        var that = this;
        var model = this.datalist[index];
        this.$Modal.confirm({
          title: "删除提示",
          content: `确定要删除分组：“${model.title}”么？`,
          onOk: () => {
            this.$axios({
              url: `/group/${model.id}`,
              method: "DELETE",
            }).then((res) => {
              if (res.code == 200) {
                this.$Message.info(res.data);
                that.getData();
              } else {
                this.$Message.error(res.msg);
              }
            });
          },
        });
      },
    },
    created() {
      this.getData();
    },
  };
  